<style type="text/css" media="screen">
/* <![CDATA[ */

    #breadcrumb {
        padding:3px;      
        margin:5px 0;  
        font-size:medium;
        border-bottom:1px solid #ccc;
    }
    #help_legend {
        margin: 3px;
        font-size: x-small;
        text-align: right;
    }
/* ]]> */
</style>
<script language="javascript" type="text/javascript" src="<?php echo get_installed_path() ?>/js/tiny_mce/tiny_mce_popup.js"></script>
<script language="javascript" type="text/javascript">
	<!--
		function insertFile(href,title,type,id){
		    if (window.opener) {
		        inst = tinyMCE.selectedInstance;
			    elm = inst.getFocusElement();
		        if (type == "img" && inst.selection.getSelectedText() == '') {
    		        var htmltext = "<img src='"+href+"' alt='"+title+"' />"
    	        } else {
    	            var htmltext = "<a href='"+href+"' title='"+title+"'>"+inst.selection.getSelectedText()+"</a>"
    	        }		    
    		    window.opener.tinyMCE.execCommand('mceInsertContent',false,htmltext);
    		    tinyMCEPopup.close();
		    } else {
    	        // implement this function on the parent holding
    	        // the iframe to get the selected file_id
    	        if (typeof(parent.insert_file_from_iframe) == "function")
    	        {
		            parent.insert_file_from_iframe(href,title,type,id);
	            } else {
	                alert('iframe function not implemented!');
	            }
		    }
		    return false;
		}
	//-->
</script>

<?php include load_template('_add.php') ?>

<div id='breadcrumb'>Browsing: <?php echo  create_breadcrumb($folder_path) ?></div>

<div id="help_legend">
    <b>Legend</b>:
    Delete File <img src="<?php echo get_installed_path()?>/images/admin/delete.gif">
    &nbsp;&nbsp;&nbsp;
    <?php 
        echo 'View type: '.form_tag($redirect, array('style'=>'display:inline')).
             hidden_field_tag('file_folder_id', $file_folder_id).
             select_tag('files_filter_by', options_for_select($file_filters, $file_filter_selected),
                        array('onchange'=>'this.form.submit()','include_blank'=>false)).
             end_form_tag();
    ?>
</div>

<table width='100%' cellpadding='2' cellspacing='1' style='border:1px solid #ccc'>
    <tr>
        <th>Name</th>
        <th width='1%'>Created</th>
        <th width='1%'></th>
    </tr>
<?php
    $odd_or_even = 0;
    if ( count($all_folders) > 0 )
    {                
        $goto = url_for($redirect);
        foreach( $all_folders as $folder )
        {
            $odd_or_even = 1 - $odd_or_even;
            if (has_access_to('Files::Delete Folders')) {
                $delete  = form_tag('delete').
                           hidden_field_tag('action','delete_folder').
                           hidden_field_tag('redirect',$redirect).
                           hidden_field_tag('file_folder_id',$file_folder_id).
                           hidden_field_tag('id',$folder['id']).
                           image_submit_tag('delete',get_installed_path().'/images/admin/delete.gif',array('onclick'=>"return delete_confirm('acl_{$l['id']}')")).
                           end_form_tag();
            } else {
                $delete = '';
            }
            echo "<tr class='alt{$odd_or_even}'>
              <td><img src='".get_installed_path()."/images/admin/icons/foldericon.png' align='absmiddle' /> ".
              link_to($folder['name'],"$goto?file_folder_id={$folder['id']}")."</td>
              <td nowrap='nowrap'>".date_format($folder['created'],"%D")."</td>
              <td nowrap='nowrap'>$delete</td>
              </tr>";
        }
    }
    if ( count($all_files) > 0 )
    {                
        foreach( $all_files as $file )
        {
            $odd_or_even = 1 - $odd_or_even;
            if (has_access_to('Files::Delete Files')) {
                $delete  = form_tag('delete').
                           hidden_field_tag('action','delete_file').
                           hidden_field_tag('redirect',$redirect).
                           hidden_field_tag('file_folder_id',$file_folder_id).
                           hidden_field_tag('id',$file['id']).
                           image_submit_tag('delete',get_installed_path().'/images/admin/delete.gif',array('onclick'=>"return delete_confirm('acl_{$l['id']}')")).
                           end_form_tag();
            } else {
                $delete = '';
            }
            $file_path = path_to_file($file['file_folder_id'])."/".rawurlencode($file['name']);
            // js function to insert file
            $file_func = '';
            $title = escape_javascript($file['name']);
            $type = preg_match("!image!i",$file['type']) ? "img" : '';            
            $file_func = "insertFile('$file_path','$title','$type', {$file['id']})";  
            
            echo "<tr class='alt{$odd_or_even}'>
                  <td>".get_icon($file['type'])." 
                  <a href='$file_path' onclick=\"$file_func;return false;\">{$file['name']}</a></td>
                  <td nowrap='nowrap'>".date_format($file['created'],"%D")."</td>
                  <td nowrap='nowrap'>$delete</td>
                  </tr>";
        }
    }
?>
</table>